package com.seashop.util;

import com.alibaba.fastjson.JSONObject;
import com.seashop.constant.ComponentConstant;

import java.util.*;

/**
 * @author moredln
 * @desc
 * @date 2020-11-05 10:53
 */
public class AppHomeUtil {

    /**
     * 解析首页配置小图标数据结构
     *
     * @param content
     * @return
     */
    public static Object parseLittleBanner(String content) {
        List list = JSONObject.parseArray(content, Object.class);
        List resultList = new ArrayList();
        for (Object obj : list) {
            JSONObject jsonObject = (JSONObject) obj;
            if (ComponentConstant.LITTER_BANNER.equals(jsonObject.getString("componentName"))) {
                resultList.add(jsonObject);
            }
        }
        return resultList;
    }

    /**
     * 解析首页配置通用数据结构
     *
     * @param content
     * @param type
     * @return
     */
    public static Object parseContent(String content, String type) {
        List list = JSONObject.parseArray(content, Object.class);
        for (Object obj : list) {
            JSONObject jsonObject = (JSONObject) obj;
            if (type.equals(jsonObject.getString("componentName"))) {
                return jsonObject;
            }
        }
        return new ArrayList<>();
    }



}
